package com.yoomiito.app.ui.search.youpin

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.home.YouPinHotSearch
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.showToast

class YouPinSearchPresenter(appConfig: AppConfig) :BaseActPresenter<YouPinSearchActivity>(appConfig){

    fun getHotSearch(){
        YmApi.getYmService()
                .youPinHotSearch
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<YouPinHotSearch>(){
                    override fun onSuccess(t: YouPinHotSearch?) {
                        v?.dismissLoading()
                        v?.setHotSearch(t)
                    }

                    override fun onFail(error: ApiException?) {
                        v?.dismissLoading()
                        error?.msg?.showToast()
                    }
                })
    }
}